#!/bin/sh

nthread=1
ncore=""
library=""
cache=""

usage()
{
cat <<EOF

Usage: fft_bench [OPTION]

Known values for OPTION are:

  --nthread=N        number of threads to run
  --library=name     name of FFT library to use
  --cache=bytes      test streaming through cache of bytes

EOF

exit $1
}

while test $# -gt 0; do

case "$1" in
    -*=*)
    arg=`echo "$1" | awk -F= '{print $1}'`
    optarg=`echo "$1" | awk -F= '{print $2}'`
      ;;

    *)
    arg=$1
    optarg=
    ;;
esac

case "$arg" in

    --library)
    library=-l$optarg
    ;;

    --nthread)
    nthread=$optarg
    ;;

    --ncore)
    ncore="-p$optarg"
    ;;

    --cache)
    cache="-c$optarg"
    ;;

    --help)
    usage 0
    ;;

    *)
    usage 1
    ;;

esac
shift
done

echo Testing $library FFT library on $nthread threads

nfft=4

rm -f fft_bench.out

while test $nfft -le 16777216; do

  echo -n "Testing nfft=$nfft "
  
  time ./fft_speed $library $cache $ncore -t$nthread -n$nfft >> fft_bench.out

  nfft=`expr $nfft '*' 2`

done

